using System;
using System.Reflection;

namespace Copperline.Escriba
{
	/// <summary>
	/// Summary description for LogEntryFieldFormatter.
	/// </summary>
	public class FieldFormatter : IField
	{
		public FieldFormatter( PropertyInfo propertyInfo, string format )
		{
			this.propertyInfo = propertyInfo;
			this.format = format;
		}

		private PropertyInfo propertyInfo;
		public PropertyInfo Property
		{
			get { return propertyInfo; }
		}

		private string format;
		public string Format
		{
			get { return format; }
		}

		public string Value( LogEntry le )
		{
			try
			{
				return Property.GetValue( le, null ).ToString();
			}
			catch( Exception )
			{
				return null;
			}
		}
	}
}
